from typing import Union, List
import uvicorn
from pydantic import BaseModel
from fastapi import FastAPI, requests, Header, Query, Header
from requests import Request
# from tortoise
from app import Base, engine
from web import websocket

appl = FastAPI()
Base.metadata.create_all(bind=engine)


appl.include_router(websocket.router)


class PageBase(BaseModel):
    page: str = None
    site: str = None
    # t: Union[List[int], None] = Query(def)


class Item(PageBase):
    item: int


@appl.get("/")
def read_root(q: PageBase):
    print(requests)
    for i in q:
        print(i)
    return q
    # return {"Hello": "World", "Wsds": 12345334}


@appl.post("/items/{item_id}", name="后视镜课代表不可计数")
# def read_item(item_id: int, item: Item, q: Union[str, None] = None):
def read_item(q: PageBase, head=Header(None)):
    """
    :param item_id:
    :param item: \n
            page 页数
            size 页容量
            item 测试数据 \n
    :param q:
    :return:
    """

    print(Header())
    print(head)
    print(Request.headers)
    return {"item_id": q}
    # return {"item_id": item_id, "q": q}


if __name__ == '__main__':
    uvicorn.run(appl, host="0.0.0.0", port=9527)



